package com.crm.controller;


import com.crm.service.UserRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author crm
 * @since 2020-06-05
 */
@RestController//标注当前类是controller类，controller用 于处理客户端请求，加Rest表示当前类的所有方法都返回json数据，不走视图
public class UserRoleController {
    @Resource//设置注入方式，spring 自动在spring容器找到叫这个名或这个类型的对象，赋给当前属性，controller调 用service
    private UserRoleService userroleService;//userrole的业务层父接口
    @RequestMapping("AddUserToRole")// 客户端请求地址
    public Object addUserToRole(Integer uid,Integer rid){
        int i=userroleService.AddUserToRole(uid,rid);
        Map<String,Object> map=new HashMap<String,Object>();
        if (i > 0) {
            map.put("code", "0");
            map.put("msg", "添加成功");

        } else {
            map.put("code", "1");
            map.put("msg", "添加失败");
        }

        return map;
    }
    @RequestMapping("RemoveUserFromRole")// 客户端请求地址
    public Object removeUserFromRole(Integer uid,Integer rid){
        int i= userroleService.RemoveUserFromRole(uid, rid);
        Map<String,Object> map=new HashMap<String,Object>();
        if (i > 0) {
            map.put("code", "0");
            map.put("msg", "删除成功");

        } else {
            map.put("code", "1");
            map.put("msg", "删除失败");
        }

        return map;
    }
}
